package com.IntelligentCommunity.community.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.IntelligentCommunity.community.domain.RealDistrict;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.IntelligentCommunity.common.log.annotation.Log;
import com.IntelligentCommunity.common.log.enums.BusinessType;
import com.IntelligentCommunity.common.security.annotation.RequiresPermissions;
import com.IntelligentCommunity.community.domain.RealUnit;
import com.IntelligentCommunity.community.service.IRealUnitService;
import com.IntelligentCommunity.common.core.web.controller.BaseController;
import com.IntelligentCommunity.common.core.web.domain.AjaxResult;
import com.IntelligentCommunity.common.core.utils.poi.ExcelUtil;
import com.IntelligentCommunity.common.core.web.page.TableDataInfo;

/**
 * 实有单位Controller
 *
 * @author IntelligentCommunity
 * @date 2024-07-23
 */
@RestController
@RequestMapping("/unit")
public class RealUnitController extends BaseController
{
    @Autowired
    private IRealUnitService realUnitService;

    /**
     * 查询实有单位列表
     */
    @GetMapping("/list")
    public TableDataInfo list(RealUnit realUnit)
    {
        startPage();
        List<RealUnit> list = realUnitService.selectRealUnitList(realUnit);
        return getDataTable(list);
    }

    /**
     * 导出实有单位列表
     */
    @Log(title = "实有单位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RealUnit realUnit)
    {
        List<RealUnit> list = realUnitService.selectRealUnitList(realUnit);
        ExcelUtil<RealUnit> util = new ExcelUtil<RealUnit>(RealUnit.class);
        util.exportExcel(response, list, "实有单位数据");
    }

    /**
     * 获取实有单位详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(realUnitService.selectRealUnitById(id));
    }

    /**
     * 新增实有单位
     */
    @Log(title = "实有单位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RealUnit realUnit)
    {
        return toAjax(realUnitService.insertRealUnit(realUnit));
    }

    /**
     * 修改实有单位
     */
    @Log(title = "实有单位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RealUnit realUnit)
    {
        return toAjax(realUnitService.updateRealUnit(realUnit));
    }

    /**
     * 删除实有单位
     */
    @Log(title = "实有单位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(realUnitService.deleteRealUnitByIds(ids));
    }
}
